{% extends 'base.html' %}

{% block title %}添加碳排放系数分类{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header">
            <h4>添加碳排放系数分类</h4>
        </div>
        <div class="card-body">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <div class="alert alert-{{ category }}">{{ message }}</div>
                    {% endfor %}
                {% endif %}
            {% endwith %}

            <form method="POST">
                <div class="mb-3">
                    <label for="name" class="form-label">分类名称</label>
                    <input type="text" class="form-control" id="name" name="name" required>
                </div>
                <div class="mb-3">
                    <label for="parent_id" class="form-label">父分类</label>
                    <select class="form-select" id="parent_id" name="parent_id">
                        <option value="0">-- 无父分类 (顶级分类) --</option>
                        {% for parent in parents %}
                            <option value="{{ parent.id }}">{{ '　' * (parent.level - 1) }}|-- {{ parent.name }} (层级: {{ parent.level }})</option>
                        {% endfor %}
                    </select>
                    <div class="form-text">选择父分类将决定当前分类层级，系统最大支持5级分类</div>
                </div>
                <div class="d-flex justify-content-between">
                    <a href="{{ url_for('coefficient_category.category_list') }}" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">添加分类</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}